import { Status, BaseFilter } from './base';

// 用户基本信息
export interface UserProfile {
  firstName: string;
  lastName: string;
  fullName: string;
  nickname?: string;
  avatar?: string;
  gender?: 'male' | 'female' | 'other';
  birthday?: string;
  phone?: string;
  email: string;
  address?: string;
  bio?: string;
}

// 用户安全设置
export interface UserSecurity {
  passwordExpiredAt?: string;
  lastPasswordChangeAt?: string;
  failedLoginAttempts: number;
  lockedUntil?: string;
  twoFactorEnabled: boolean;
  loginNotification: boolean;
}

// 用户偏好设置
export interface UserPreferences {
  language: string;
  timezone: string;
  theme: 'light' | 'dark' | 'auto';
  dateFormat: string;
  timeFormat: '12h' | '24h';
  notifications: {
    email: boolean;
    sms: boolean;
    push: boolean;
  };
}

// 用户实体
export interface User {
  id: string;
  tenantId: string;
  organizationId: string;
  username: string;
  profile: UserProfile;
  status: Status;
  roles: string[]; // 角色ID数组
  departments: string[]; // 部门ID数组
  positions: string[]; // 岗位ID数组
  tenantIds: string[]; // 多租户支持
  organizationIds: string[]; // 多组织支持
  security: UserSecurity;
  preferences: UserPreferences;
  lastLoginAt?: string;
  lastLoginIp?: string;
  loginCount: number;
  createdAt: string;
  updatedAt: string;
  createdBy?: string;
  updatedBy?: string;
}

// 用户查询过滤器
export interface UserFilter extends BaseFilter {
  tenantId?: string;
  organizationId?: string;
  roleId?: string;
  departmentId?: string;
  positionId?: string;
  lastLoginStart?: string;
  lastLoginEnd?: string;
  email?: string;
  phone?: string;
}

// 用户表单数据
export interface UserFormData {
  username: string;
  profile: Partial<UserProfile>;
  status: Status;
  roles: string[];
  departments: string[];
  positions: string[];
  organizationId: string;
  tenantIds?: string[];
  organizationIds?: string[];
  password?: string;
  confirmPassword?: string;
  preferences?: Partial<UserPreferences>;
}

// 创建用户请求
export interface CreateUserRequest extends UserFormData {
  tenantId: string;
  password: string;
}

// 更新用户请求
export interface UpdateUserRequest extends Partial<Omit<UserFormData, 'password' | 'confirmPassword'>> {}

// 修改密码请求
export interface ChangePasswordRequest {
  oldPassword: string;
  newPassword: string;
  confirmPassword: string;
}

// 重置密码请求
export interface ResetPasswordRequest {
  userId: string;
  newPassword: string;
  confirmPassword: string;
}

// 用户简化信息（用于下拉选择等）
export interface UserSimple {
  id: string;
  username: string;
  fullName: string;
  email: string;
  avatar?: string;
  status: Status;
}

// 登录凭据
export interface LoginCredentials {
  username: string;
  password: string;
  tenantCode?: string;
  captcha?: string;
  rememberMe?: boolean;
}

// 登录响应
export interface LoginResponse {
  user: User;
  token: string;
  refreshToken: string;
  expiresIn: number;
  permissions: string[];
  currentTenant: {
    id: string;
    name: string;
    code: string;
  };
  currentOrganization: {
    id: string;
    name: string;
    code: string;
  };
}